import myAxios from "@/util/request";
import request from "@/util/request";

/**
 * 查角色
 */
export const listRole = async (pageNum:number, pageSize:number, name:string) => {
    return myAxios.request({
        url: "/role/search",
        method: "GET",
        headers: {
            "Authorization": localStorage.getItem("token"),
        },
        params: {
            pageNum: pageNum,
            pageSize: pageSize,
            name: name,
        }
    })
}

/**
 * 删除角色
 */
export const delRole = (roleId: number) => {
    return myAxios({
        url: '/role/del',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "roleId": roleId
        }
    });
};

interface addRoleParam {
    roleName: string,
    sort: number
}

export const addRole = (param: addRoleParam) => {
    return myAxios({
        url: '/role/add',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data: param
    });
};

interface modifyRoleParam {
    roleId: number
    roleName: string,
    sort: number
}

export const modifyRole = (param: modifyRoleParam) => {
    return myAxios({
        url: '/role/modify',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data: param
    });
};

export const bindRolePermission = (data: {
    roleId: number;
    permissionIdList: string[]
}) => {
    return request({
        url: '/role/bind',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('adminToken')
        },
        data
    });
};

/**
 * 角色详情
 */
export const roleDetail = async (roleId: number) => {
    return myAxios.request({
        url: "/role/detail",
        method: "GET",
        headers: {
            "Authorization": localStorage.getItem("token"),
        },
        params: {
            roleId: roleId,
        }
    })
}






